﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XNA_TD
{
    abstract public class Tower : GameObject
    {
        public Tower(Vector3 pos, string tower)
            : base(Priority.Tower, pos, GegnerTyp.Boden, tower)
        {
            turretYaw = -(float)Math.PI / 2;
        }

        public int VerkaufsPreis()
        {
            return (int) (gesamtPreis *.5f);
        }

        public override void FixedGameUpdate()
        {
            base.FixedGameUpdate();
            if (target == null && lvlInfo.attackRange > 0)
            {
                foreach (var render in gameManager.getRenderList(Priority.Einheit))
                {
                    var unit = render as Unit;
                    if (unit != null)
                    {
                        if ((unit.typ & lvlInfo.angreifbar) != 0)
                        {
                            if ((position - unit.position).Length() < lvlInfo.attackRange)
                            {
                                target = unit;
                                return;
                            }
                        }
                    }
                }
            }
        }

        public override void Load()
        {
            base.Load();
            position.Y = terrain.getHeight(position.X, position.Z);
            turretPos.Y = position.Y + .3f;
            map.Bauen(position);
            geld -= lvlInfo.preis;
            gesamtPreis += lvlInfo.preis;
        }

        public override void UnLoad()
        {
            base.UnLoad();
            map.Entfernen(position);
        }
    }
}
